﻿using Wx.Core;
using Utilities.Log;
namespace Wx.Api
{
    public static class Menu
    {
        private static LogHelper log = new LogHelper(typeof(Menu));
        public static bool CreateMeun(string menu)
        {
            string url = string.Format(Config.GetApiUrl("createmenu"), Token.AccessToken);
            Model.HttpResult result = HttpUtility.Post(url, menu);
            if (result.msg.Contains("errcode"))
            {
                log.error("Create Menu Error!Error Msg:" + result.msg);
                return true;
            }
            else
            {
                log.info("Create Menu Ok!Menu:" + result.msg);
                return false;
            }
        }

        public static string QueryMenu()
        {
            string url = string.Format(Config.GetApiUrl("querymenu"), Token.AccessToken);
            Model.HttpResult result = HttpUtility.Get(url);
            if (result.msg.Contains("errcode"))
            {
                log.error("Query Menu Error!Error Msg:" + result.msg);
                return string.Empty;
            }
            else
            {
                log.info("Query Menu OK!Menu Msg:" + result.msg);
                return result.msg;
            }
        }

        public static bool DeleteMenu()
        {
            string url = string.Format(Config.GetApiUrl("deletemenu"), Token.AccessToken);
            Model.HttpResult result = HttpUtility.Get(url);
            if (result.msg.Contains("errcode"))
            {
                log.error("Delete Menu Error!Error Msg:" + result.msg);
                return false;
            }
            else
            {
                log.info("Delete Menu OK!Msg:" + result.msg);
                return true;
            }
        }

        public static bool CreatePersonalMenu(string menu)
        {
            string url = string.Format(Config.GetApiUrl("createpersonalmenu"), Token.AccessToken);
            Model.HttpResult result = HttpUtility.Post(url, menu);
            if (result.msg.Contains("errcode"))
            {
                log.error("Create Personal Menu Error!Error Msg:" + result.msg);
                return true;
            }
            else
            {
                log.info("Create Personal Menu Ok!Menu:" + result.msg);
                return false;
            }
        }

        public static bool DeletePersonalMenu(string mid)
        {
            string url = string.Format(Config.GetApiUrl("deletePersonalmenu"), Token.AccessToken);
            Model.HttpResult result = HttpUtility.Post(url, mid);
            if (result.msg.Contains("errcode"))
            {
                log.error("Delete Personal Menu Error!Error Msg:" + result.msg);
                return false;
            }
            else
            {
                log.info("Delete Personal Menu OK!Msg:" + result.msg);
                return true;
            }
        }
    }
}
